


kernel void dict_bgr2z(global const float *dict,global const char* buff, global float* dst)  
{  

    int x = (int)get_global_id(0);  
    int y = (int)get_global_id(1);  

    unsigned char b_tmp = buff[(x + y*1280)*4];
    unsigned char g_tmp = buff[(x + y*1280)*4 + 1];
    unsigned char r_tmp = buff[(x + y*1280)*4 + 2];
    float b = (float)b_tmp ;
    float g = (float)g_tmp ;
    float r = (float)r_tmp ;
    
//    printf("b:%f g:%f r:%f\n",b,g,r);
	if (r <= 10.0f)
	{
		r = r / (255.0f*12.0f) ;
		g = g / (255.0f) ;
		b = b / (255.0f) ;
	}
	else
	{
		r = dict[(int)r] ;
		
		if (g <= 10.0f)
		{
			g = g / (255.0f * 12.0f) ;
			b = b / (255.0f) ;
		}
		else
		{
			g = dict[(int)g] ;
			if (b <= 10.0f)
			{
				b = b / (255.0f * 12.0f);
			}
			else
			{
				b = dict[(int)b] ;
			}
		}
	}

	float Z = 0.019334 * r + 0.119193 * g + 0.950527 * b;
//	printf("b:%f g:%f r:%f Z:%f\n",b,g,r,Z);
	dst[x*800+y] = Z ;
}  